package top.guoyang.springboot3.entity.auth;

import com.baomidou.mybatisplus.annotation.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import top.guoyang.springboot3.validate.CommonValidate;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@Data
@TableName("tb_user")
public class TbUser implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    // 自增主键
    @TableId(type = IdType.AUTO)
    private  Integer id;


    @NotBlank(message = "登录名必须填写",groups = {CommonValidate.Add.class})
    @Length(min = 3,max = 16,message = "登录名长度必须在3-16之间",groups = {CommonValidate.Add.class})
    private  String username;

    @NotBlank(message = "登录密码必须填写",groups = {CommonValidate.Add.class,CommonValidate.Edit.class})
    @Length(min = 3,max = 16,message = "登录密码长度必须在3-16之间",groups = {CommonValidate.Add.class,CommonValidate.Edit.class})
    private  String password;

    @NotBlank(message = "姓名必须填写",groups = {CommonValidate.Add.class})
    private  String nickname;

    private  String salt;
    @TableField(insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private  String deleted;
    private  Integer role;
    @TableField(insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private Date created;

    public TbUser view(){
        TbUser user  = new TbUser();
        user.setId(id);
        user.setUsername(username);
        user.setNickname(nickname);
        user.setRole(role);
        user.setCreated(created);
        return user;
    }


}
